<template>
  <div>
    <div class="flex flex-col h-full">
      <SearchContainer @search="queryList" @reset="() => formRef.resetFields()">
        <a-form ref="formRef" class="flex-1" :model="formState" :colon="false" :label-col="{ style: { width: '70px' } }">
          <a-form-item name="mcbh" class="w-64">
            <a-input v-model:value="formState.mcbh" placeholder="频次编号/频次名称/助记码" />
          </a-form-item>
        </a-form>
      </SearchContainer>
      <a-card class="mt-2 flex-1">
        <div class="flex justify-end mb-3">
          <BaseExport type="运维" name="给药频次" code="00001061" :search-params="formState">导出</BaseExport>
        </div>
        <BaseTable
          :loading="loading"
          column-code="00001061"
          fill
          :data-source="tableData"
          bordered
          :pagination="{ total: page.total, current: page.current, pageSize: page.pageSize }"
          @change="onPageChange"
        >
          <template #bodyCell="{ column, index }">
            <template v-if="column.dataIndex === 'xh'">
              {{ index + 1 }}
            </template>
          </template>
        </BaseTable>
      </a-card>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { post } from '@/utils/request'
import SearchContainer from '@/components/SearchContainer'
import BaseTable from '@/components/BaseTable'

const loading = ref(false)
const tableData = ref([])
const formRef = ref(null)
const page = ref({ total: 0, current: 1, pageSize: getSystemConfig('DFFAULT_PAGE_SHOW_COUNT') || 10 })
const formState = ref({})

const queryList = async () => {
  loading.value = true
  const { code, data, total } = await post('/operation/opex/getFrequencyMedicineDictInfoList', {
    mcbh: formState.value.mcbh,
    pageNum: page.value.current,
    pageSize: page.value.pageSize
  })
  if (code !== 0) return
  tableData.value = data
  loading.value = false
  page.value.total = total
}
const onPageChange = ({ current, pageSize }) => {
  page.value.current = current
  page.value.pageSize = pageSize
  queryList()
}
onMounted(() => {
  queryList()
})
</script>
<style lang="less" scoped>
.ant-picker {
  width: 100%;
}
</style>
